package com.benchmark.springboot.controller;

import com.benchmark.springboot.model.SimpleRespInfo;
import com.power.common.model.CommonResult;
import com.power.common.util.IpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 基本接口访问
 * @author yu 2019/10/17.
 */
@RestController
public class IndexController {

    @Value("{app.version:v1.0}")
    private String version;

    /**
     * 默认访问根路径
     * @apiNote 容器化滚动升级和灰度部署测试可以在yml中指定app.version版本方便观察应用
     * @return
     */
    @GetMapping("/")
    public CommonResult<SimpleRespInfo> index() throws UnknownHostException {
        InetAddress ia = InetAddress.getLocalHost();
        SimpleRespInfo respInfo = new SimpleRespInfo();
        respInfo.setHostName(ia.getHostName());
        respInfo.setServerIp(IpUtil.getServerIp());
        respInfo.setVersion(version);
        return CommonResult.ok().setResult(respInfo);
    }
}
